package ar.fiuba.tp7552.buildadmin.webactions.planes;

import java.util.Collection;

import com.opensymphony.xwork2.Preparable;

import ar.fiuba.tp7552.buildadmin.model.builds.Edificio;
import ar.fiuba.tp7552.buildadmin.service.EdificioService;
import ar.fiuba.tp7552.buildadmin.service.PlanService;
import ar.fiuba.tp7552.buildadmin.webactions.BaseAction;

public class LiquidarPlanAction extends BaseAction implements Preparable {
	
	private EdificioService edificioService;
	private PlanService planService;
	
	private Edificio edificio;

	// ~~ Constructor ====================================================
	public LiquidarPlanAction(EdificioService edificioService, PlanService planService) {
		super();
		this.edificioService = edificioService;
		this.planService = planService;
	}
	
	

	// ~~ Actions ========================================================
	
	@Override
	public void prepare() throws Exception {
		if (edificio != null && edificio.getId() != null) {
			edificio = edificioService.get(edificio.getId());
		}
	}

	public String load() {
		return BaseAction.SUCCESS;
	}
	
	public String liquidar() {
		planService.liquidar(edificio);
		return BaseAction.SUCCESS;
	}
	
	// ~~ getters y setters ========================================================
	public Collection<Edificio> getEdificios() {
		return edificioService.getAll();
	}
	public Edificio getEdificio() {
		return edificio;
	}
	public void setEdificio(Edificio edificio) {
		this.edificio = edificio;
	}
}
